var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("Util"),
    d = e("ConfigGameData"),
    u = e("GameData"),
    p = e("LoginProxy"),
    h = e("SkinLevelData"),
    f = cc._decorator,
    _ = f.ccclass,
    y = f.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.lab_player_count = null),
                (t.node_btn_exit = null),
                (t.userIcons = null),
                (t.target_parent_act = null),
                (t._currPlayerCount = 0),
                (t._maxPlayerCount = 16),
                (t._isInventedMatch = !1),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                this.isCache = !1;
            }),
            (t.prototype.onResetView = function () {
                e.prototype.onResetView.call(this), this.init();
            }),
            (t.prototype.registerMediator = function () {
                e.prototype.registerMediator.call(this);
            }),
            (t.prototype.removeMediator = function () {
                e.prototype.removeMediator.call(this);
            }),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this);
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this);
            }),
            (t.prototype.onClickExit = function () {
                this.closeView(!1);
            }),
            (t.prototype.init = function () {
                var e = this;
                this.scheduleOnce(function () {
                    e.simulationMatch(e._currPlayerCount, e._maxPlayerCount, function () {
                        e.scheduleOnce(function () {
                            e.onJoinGame();
                        }, 0.5);
                    });
                }, 0.3);
                var t = 0;
                this.node.runAction(
                    cc.repeatForever(
                        cc.sequence(
                            cc.delayTime(0.3),
                            cc.callFunc(function () {
                                t++;
                                for (var o = "loading ", n = 0; n < t; n++) o += ".";
                                t > 2 && (t = 0),
                                    (e.node
                                        .getChildByName("content")
                                        .getChildByName("label_loading")
                                        .getComponent(cc.Label).string = o);
                            })
                        )
                    )
                ),
                    (this.target_parent_act = this.node.getChildByName("content").getChildByName("target_parent_act")),
                    this.playAni();
            }),
            (t.prototype.refreshCurrPlayerCount = function (e, t) {
                this.lab_player_count.string = "已加入玩家 " + e + "/" + t;
                var o = d.default.instance.GetAIName(e - 1);
                if ((0 == e && (o = u.default.instance.UserName), !(e >= 16))) {
                    var n = this.userIcons.children[e].getChildByName("mask").getChildByName("user_icon");
                    if (o == u.default.instance.UserName)
                        game.appFacade.retrieveProxy(p.default.NAME).loginVO.userInfo,
                            cc.assetManager.loadBundle("popup", function (e, t) {
                                if (!e) {
                                    var o = u.default.instance.getUserSkin(),
                                        i = h.SkinLevelData.instance.skinList[o];
                                    t.load("textures/EggView/skin_icon/" + i.name, cc.SpriteFrame, function (e, t) {
                                        if (e)
                                            return (
                                                console.log("加载头像出错：", "textures/EggView/skin_icon/" + i.name),
                                                void cc.error(e.message || e)
                                            );
                                        n.getComponent(cc.Sprite).spriteFrame = t;
                                    });
                                }
                            });
                    else {
                        var i = d.default.instance.getIconByAIName(o);
                        console.log("这个是什么：", i),
                            cc.assetManager.loadBundle("popup", function (e, t) {
                                e ||
                                    t.load(i, cc.SpriteFrame, function (e, o) {
                                        if (e)
                                            return (
                                                console.log("排位加载头像出错：", i),
                                                void t.load(
                                                    "textures/EggView/skin_icon/kitty",
                                                    cc.SpriteFrame,
                                                    function (e, t) {
                                                        if (e)
                                                            return (
                                                                console.log("排位加载头像出错：", i),
                                                                void cc.error(e.message || e)
                                                            );
                                                        n.getComponent(cc.Sprite).spriteFrame = t;
                                                    }
                                                )
                                            );
                                        n.getComponent(cc.Sprite).spriteFrame = o;
                                    });
                            });
                    }
                }
            }),
            (t.prototype.onDisable = function () {
                this.stopAni();
            }),
            (t.prototype.playAni = function () {
                this.target_parent_act.children.forEach(function (e, t) {
                    var o = e.position;
                    (e.scale = 0), (e.position = cc.v3(0, 0, 0));
                    var n = cc.scaleTo(0.5, 0),
                        i = cc.moveTo(0.5, cc.v2(0, 0)),
                        a = cc.spawn(n, i),
                        r = cc.scaleTo(0.5, 1),
                        s = cc.moveTo(0.5, cc.v2(o.x, o.y)),
                        c = cc.spawn(r, s),
                        l = 0.1 * t,
                        d = 1 - l,
                        u = cc.sequence(cc.delayTime(l), c, a, cc.delayTime(d)),
                        p = cc.repeatForever(u);
                    e.runAction(p);
                });
            }),
            (t.prototype.stopAni = function () {
                this.target_parent_act.children.forEach(function (e) {
                    e.stopAllActions();
                });
            }),
            (t.prototype.simulationMatch = function (e, t, o) {
                var n = this;
                this._isInventedMatch ||
                    ((this._isInventedMatch = !0),
                    this.refreshCurrPlayerCount(e, t),
                    this.scheduleOnce(function i() {
                        e++,
                            (n._currPlayerCount = e),
                            n.refreshCurrPlayerCount(e, t),
                            e < t
                                ? n.scheduleOnce(function () {
                                      i();
                                  }, l.default.randomFrom(1, 10) / 10)
                                : o && o();
                    }, l.default.randomFrom(1, 10) / 10));
            }),
            (t.prototype.onJoinGame = function () {
                game.UIManager.instance.showLoadResView([c.default.Game], [c.default.Game], function () {
                    game.UIManager.instance.replaceModuleView(
                        c.default.Game,
                        s.default.GameBundle.prefabs.assetsList.GameModuleView,
                        {}
                    );
                });
            }),
            (t.ON_CLICK_EXIT = "ON_CLICK_EXIT"),
            r([y(cc.Label)], t.prototype, "lab_player_count", void 0),
            r([y(cc.Node)], t.prototype, "node_btn_exit", void 0),
            r([y(cc.Node)], t.prototype, "userIcons", void 0),
            r([_], t)
        );
    })(game.BasePopView);
i.default = m;
